package xstr

import (
	"github.com/gogf/gf/v2/crypto/gaes"
	"github.com/gogf/gf/v2/encoding/gbase64"
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/os/gctx"
)

var (
	ctx    = gctx.GetInitCtx()
	aesKey string
)

func init() {

	sAesKey, err := g.Cfg().Get(ctx, "encrypt.aesKey")
	if err != nil {
		panic(err)
	}
	aesKey = sAesKey.String()
}

// EncryptPassword 加密密码
func EncryptPassword(password, salt string) string {
	bytes, err := gaes.Encrypt([]byte(password), []byte(aesKey), []byte(salt))
	if err != nil {
		panic(err)
	}

	return gbase64.EncodeToString(bytes)
}
